namespace RkCalendar
{
    public static class ConsoleWriter
    {
        public static void WriteLine(string text)
        {
            string[] strs = text.Split('{', '}');
            ConsoleColor color;
            foreach (var str in strs)
            {
                if (str.StartsWith("-") || str.StartsWith("+"))
                {
                    foreach (var cs in str.Split(','))
                    {
                        if (Enum.TryParse<ConsoleColor>(cs.Substring(1), out color))
                        {
                            if (cs.StartsWith("-"))
                                Console.BackgroundColor = color;
                            else
                                Console.ForegroundColor = color;
                        }
                    }
                }
                else if (str.Equals("/"))
                {
                    Console.ResetColor();
                }
                else
                    Console.Write(str);
            }
            Console.ResetColor();
            Console.Write('\n');
        }

        public static void Write(string text, ConsoleColor? backColor = null, ConsoleColor? foreColor = null)
        {
            if (backColor.HasValue)
                Console.BackgroundColor = backColor.Value;
            if (foreColor.HasValue)
                Console.ForegroundColor = foreColor.Value;
            Console.Write(text);
            Console.ResetColor();
        }
    }
}


